<template>
  <div>
    <el-form :model="formItem" label-width="100px" size="mini" class="form-view">
      <el-row>
        <el-col :span="12">
          <el-form-item label="标题" prop="title">
            {{ formItem.title }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="接收日期" prop="receiveDate">
            {{ formItem.receiveDate }}
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="资产明细">
            <el-table
              :loading="false"
              :data="formItem.assetList"
              border
              class="fixed-table-table"
              size="mini"
              max-height="240px"
            >
              <el-table-column
                label="序号"
                type="index"
                width="50"
                header-align="center"
                align="center"
              />
              <el-table-column v-for="column in insideColumns" :key="column.key" header-align="center" align="center" :label="column.title" :prop="column.key" :sortable="column.sortable">
                <template slot-scope="scope">
                  <column-render :render="column.render" :row="scope.row" :column="column" />
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { detail } from '@neu/dcam-ui/api/rukuFinanceSL'
import { formatDate } from '@neu/biz-core/utils/utils'

const formItem = {
  title: '',
  receiveDate: '',
  assetList: []
}
export default {
  components: {
  },
  props: {
    taskId: {
      required: false,
      type: String,
      default: 'NULL'
    },
    workOrderNum: {
      required: false,
      type: String,
      default: ''
    }
  },
  data() {
    return {
      formItem: {
        ...formItem
      },
      // insideColumns: [
      //   { title: '资产名称', width: 140, key: 'name', sortable: 'custom', display: true },
      //   { title: '大分类', width: 100, key: 'bigTypeName', sortable: 'custom', display: true },
      //   { title: '中分类', width: 100, key: 'middleTypeName', sortable: 'custom', display: true },
      //   { title: '小分类', width: 100, key: 'smallTypeName', sortable: 'custom', display: true },
      //   { title: '数量', width: 100, key: 'amount', sortable: 'custom', display: true },
      //   { title: '计量单位', width: 100, key: 'measureUnit', sortable: 'custom', display: true },
      //   { title: '供应商', width: 100, key: 'supplierName', sortable: 'custom', display: true },
      //   { title: '序列号', width: 100, key: 'serialnumber', sortable: 'custom', display: true },
      //   { title: '资产卡片', width: 100, key: 'card', sortable: 'custom', display: true }
      // ]
      insideColumns: [
        { title: '资产名称', width: 140, key: 'name', sortable: 'custom', display: true },
        { title: '资产卡片', width: 100, key: 'card', sortable: 'custom', display: true },
        { title: '资产分类', key: 'type',
          render: (h, params) => {
            let txt = params.row.smallTypeName
            if (params.row.middleTypeName) {
              txt = params.row.middleTypeName + ' / ' + txt
            }
            if (params.row.bigTypeName) {
              txt = params.row.bigTypeName + ' / ' + txt
            }
            return h('span', txt)
          }
        },
        { title: '购置日期', width: 100, key: 'purchaseDate', render: (h, params) => { return h('span', formatDate(params.row.purchaseDate, 'YYYY-MM-DD')) }, display: true },
        { title: '品牌', width: 100, key: 'brand', sortable: 'custom', display: true },
        { title: '规格型号', width: 100, key: 'specifications', sortable: 'custom', display: true },
        { title: '序列号', width: 100, key: 'serialnumber', sortable: 'custom', display: true },
        { title: '计量单位', width: 100, key: 'measureUnit', sortable: 'custom', display: true },
        { title: '数量', width: 100, key: 'amount', sortable: 'custom', display: true },
        { title: '使用期限', width: 100, key: 'usePeriod', display: true },
        { title: '金额', width: 100, key: 'money', sortable: 'custom', display: true },
        { title: '用途', width: 100, key: 'purpose', display: true }
      ]
    }
  },
  created() {
    this.fetch()
  },
  methods: {
    // 获取借用工单信息
    fetch() {
      if (this.workOrderNum !== 'NULL') {
        detail(this.workOrderNum, this.taskId).then(response => {
          response.data.assetList = response.data.assetList.sort((a, b) => b.id - a.id)
          this.formItem = {
            ...response.data
          }
          this.formItem.receiveDate = formatDate(this.formItem.receiveDate, 'YYYY-MM-DD')
        })
      } else {
        this.formItem = {
          ...formItem
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .fixed-table-table {
    margin: 8px 8px 8px 0;
  }
</style>
